<script setup>
import { expClassListService } from "@/api";
import { ref, onMounted } from "vue";

defineProps({
  categoryId: {
    type: [Number, String],
  },
  width: {
    type: String,
    default: "width: 190px",
  },
});

const emit = defineEmits(["update:categoryId"]);
const channelList = ref([]);
const getChannelList = async () => {
  const { data } = await expClassListService({
    pageNum: 1,
    pageSize: 20,
  });
  console.log(data);
  let res = data.records.map((item) => {
    let li = {
      id: item.categoryId,
      categoryName: item.categoryName,
    };
    return li;
  });
  channelList.value = res;
};
onMounted(() => {
  getChannelList();
});
</script>
<template>
  <el-select
    clearable
    :style="width"
    :modelValue="categoryId"
    @update:categoryId="emit('update:categoryId', $event)"
  >
    <el-option
      v-for="channel in channelList"
      :key="channel.id"
      :label="channel.categoryName"
      :value="channel.id"
    ></el-option>
  </el-select>
</template>
